package com.projetIE.prudhomme_duisit.meteodata;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * <p>
 * Java class for meteoDataResponse complex type.
 * 
 * <p>
 * The following schema fragment specifies the expected content contained within
 * this class.
 * 
 * <pre>
 * &lt;complexType name="meteoDataResponse">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element ref="{http://www.projetIE.com/prudhomme_duisit/meteoData}response"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "meteoDataResponse", propOrder = { "response" })
public class MeteoDataResponse {
	
	@XmlElement(required = true)
	protected Response	response;
	
	/**
	 * Gets the value of the response property.
	 * 
	 * @return possible object is {@link Response }
	 * 
	 */
	public Response getResponse() {
		return response;
	}
	
	/**
	 * Sets the value of the response property.
	 * 
	 * @param value
	 *            allowed object is {@link Response }
	 * 
	 */
	public void setResponse(Response value) {
		this.response = value;
	}
	
	public Document generatedDom() {
		DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder;
		Document doc = null;
		try {
			docBuilder = dbfac.newDocumentBuilder();
			
			doc = docBuilder.newDocument();
			
			doc.setXmlVersion("1.0");
			
			Element situationMeteo = doc.createElement("situation-meteo");
			
			Element requeteMeteo = doc.createElement("requete-meteo");
			situationMeteo.appendChild(requeteMeteo);
			
			Element client = doc.createElement("client");
			client.setTextContent(response.getRequeteMeteo().getClient());
			requeteMeteo.appendChild(client);
			
			Element country = doc.createElement("pays");
			if (response.getRequeteMeteo().getPays() == null) {
				country.setTextContent("");
			} else {
				country.setTextContent(response.getRequeteMeteo().getPays());
			}
			requeteMeteo.appendChild(country);
			
			Element city = doc.createElement("ville");
			if (response.getRequeteMeteo().getVille() == null) {
				city.setTextContent("");
			} else {
				city.setTextContent(response.getRequeteMeteo().getVille());
			}
			requeteMeteo.appendChild(city);
			
			Element responseMeteo = doc.createElement("reponse-meteo");
			situationMeteo.appendChild(responseMeteo);
			
			Element meteo = doc.createElement("meteo");
			responseMeteo.appendChild(meteo);
			
			Element lieu = doc.createElement("lieu");
			if (response.getReponseMeteo().getMeteo().getLieu() == null) {
				lieu.setTextContent("");
			} else {
				lieu.setTextContent(response.getReponseMeteo().getMeteo().getLieu());
			}
			meteo.appendChild(lieu);
			
			Element dateHeure = doc.createElement("date-heure");
			if (response.getReponseMeteo().getMeteo().getDateHeure() == null) {
				dateHeure.setTextContent("");
			} else {
				dateHeure.setTextContent(response.getReponseMeteo().getMeteo().getDateHeure());
			}
			meteo.appendChild(dateHeure);
			
			Element vent = doc.createElement("vent");
			if (response.getReponseMeteo().getMeteo().getVent() == null) {
				vent.setTextContent("");
			} else {
				vent.setTextContent(response.getReponseMeteo().getMeteo().getVent());
			}
			meteo.appendChild(vent);
			
			Element visibilite = doc.createElement("visibilite");
			if (response.getReponseMeteo().getMeteo().getVisibilite() == null) {
				visibilite.setTextContent("");
			} else {
				visibilite.setTextContent(response.getReponseMeteo().getMeteo().getVisibilite());
			}
			meteo.appendChild(visibilite);
			
			Element ciel = doc.createElement("ciel");
			if (response.getReponseMeteo().getMeteo().getCiel() == null) {
				ciel.setTextContent("");
			} else {
				ciel.setTextContent(response.getReponseMeteo().getMeteo().getCiel());
			}
			meteo.appendChild(ciel);
			
			Element temperature = doc.createElement("temperature");
			if (response.getReponseMeteo().getMeteo().getTemperature() == null) {
				temperature.setTextContent("");
			} else {
				temperature.setTextContent(response.getReponseMeteo().getMeteo().getTemperature());
			}
			meteo.appendChild(temperature);
			
			Element pointRosee = doc.createElement("point-rosee");
			if (response.getReponseMeteo().getMeteo().getPointRosee() == null) {
				pointRosee.setTextContent("");
			} else {
				pointRosee.setTextContent(response.getReponseMeteo().getMeteo().getPointRosee());
			}
			meteo.appendChild(pointRosee);
			
			Element humidite = doc.createElement("humidite");
			if (response.getReponseMeteo().getMeteo().getHumidite() == null) {
				humidite.setTextContent("");
			} else {
				humidite.setTextContent(response.getReponseMeteo().getMeteo().getHumidite());
			}
			meteo.appendChild(humidite);
			
			Element pression = doc.createElement("pression");
			if (response.getReponseMeteo().getMeteo().getPression() == null) {
				pression.setTextContent("");
			} else {
				pression.setTextContent(response.getReponseMeteo().getMeteo().getPression());
			}
			meteo.appendChild(pression);
			
			Element status = doc.createElement("status");
			if (response.getReponseMeteo().getMeteo().getStatus() == null) {
				status.setTextContent("");
			} else {
				status.setTextContent(response.getReponseMeteo().getMeteo().getStatus());
			}
			meteo.appendChild(status);
			
			doc.appendChild(situationMeteo);
			
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		}
		return doc;
	}
	
}
